<?php
namespace app\api\model;

use think\Model;

class User extends Base
{
    protected $table = 'user';
    protected $autoWriteTimestamp = 'datetime';

    public function newUser($openid='',$userInfo=[])
    {
        $user = $this->where('openid',$openid)->find();

        if (!$user){

            $user = $this->create([
                'openid'=>$openid,
                'nickname'=>$userInfo['nickName'],
                'sex'=>$userInfo['gender'],
                'city'=>$userInfo['city'],
                'province'=>$userInfo['province'],
                'country'=>$userInfo['country'],
                'avatar'=>$userInfo['avatarUrl']
            ]);

        }

        return $user->id;

    }

}